//
//  HZPeiziMoneyFlowCell.m
//  Stock_Stategy
//
//  Created by MayerF on 2017/12/13.
//  Copyright © 2017年 MayerF. All rights reserved.
//

#import "HZPeiziMoneyFlowCell.h"

@implementation HZPeiziMoneyFlowModel
@end

@interface HZPeiziMoneyFlowCell()
@property (nonatomic, strong)UILabel *pOneLabel;
@property (nonatomic, strong)UILabel *pTwoLabel;
@property (nonatomic, strong)UILabel *pThreeLabel;
@property (nonatomic, strong)UILabel *pFourLabel;
@property (nonatomic, strong)UILabel *pOneDownLabel;
@property (nonatomic, strong)UILabel *pTwoDownLabel;
@property (nonatomic, strong)UILabel *pThreeDownLabel;
@property (nonatomic, strong)UILabel *pFourDownLabel;
@end

@implementation HZPeiziMoneyFlowCell

+ (HZPeiziMoneyFlowCell *)cellTableView:(UITableView *)tableView
                             indexPath:(NSIndexPath *)indexPath
                             cellModel:(HZPeiziMoneyFlowModel *)cellModel
{
    static NSString *ID = @"peizi_addMoneyCell";
    HZPeiziMoneyFlowCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[HZPeiziMoneyFlowCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        [cell p_commonInit];
        [cell p_initConstraints];
    }
    [cell p_updateDataWithmodel:cellModel indexPath:indexPath];
    
    return cell;
}

- (void)p_commonInit
{
    _pOneLabel = [UILabel new];
    _pTwoLabel = [UILabel new];
    _pThreeLabel = [UILabel new];
    _pFourLabel = [UILabel new];
    _pOneDownLabel = [UILabel new];
    _pTwoDownLabel = [UILabel new];
    _pThreeDownLabel = [UILabel new];
    _pFourDownLabel = [UILabel new];
    
    _pOneLabel.textAlignment = _pTwoLabel.textAlignment =
    _pThreeLabel.textAlignment = _pFourLabel.textAlignment = NSTextAlignmentCenter;
    _pOneDownLabel.textAlignment = _pTwoDownLabel.textAlignment =
    _pThreeDownLabel.textAlignment = _pFourDownLabel.textAlignment = NSTextAlignmentCenter;
    _pOneLabel.font = _pTwoLabel.font = _pThreeLabel.font =
    _pFourLabel.font = _pOneDownLabel.font = _pTwoDownLabel.font =
    _pThreeDownLabel.font = _pFourDownLabel.font = [UIFont systemFontOfSize:15];
}

- (void)p_initConstraints
{
    [self.contentView addSubview:_pOneLabel];
    [self.contentView addSubview:_pTwoLabel];
    [self.contentView addSubview:_pThreeLabel];
    [self.contentView addSubview:_pFourLabel];
    [self.contentView addSubview:_pOneDownLabel];
    [self.contentView addSubview:_pTwoDownLabel];
    [self.contentView addSubview:_pThreeDownLabel];
    [self.contentView addSubview:_pFourDownLabel];
    
    [_pOneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self);
        make.left.mas_equalTo(self);
        make.right.mas_equalTo(_pTwoLabel.mas_left);
        make.bottom.mas_equalTo(_pOneDownLabel.mas_top);
    }];
    [_pTwoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(_pOneLabel);
        make.right.mas_equalTo(_pThreeLabel.mas_left);
    }];
    [_pThreeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(_pTwoLabel);
        make.right.mas_equalTo(_pFourLabel.mas_left);
    }];
    [_pFourLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(_pThreeLabel);
        make.right.mas_equalTo(self);
        make.width.mas_equalTo(@[_pOneLabel, _pTwoLabel, _pThreeLabel]);
    }];
    [_pOneDownLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self);
        make.left.height.mas_equalTo(_pOneLabel);
        make.right.mas_equalTo(_pTwoDownLabel.mas_left);
    }];
    [_pTwoDownLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(_pOneDownLabel);
        make.right.mas_equalTo(_pThreeDownLabel.mas_left);
    }];
    [_pThreeDownLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(_pTwoDownLabel);
        make.right.mas_equalTo(_pFourDownLabel.mas_left);
    }];
    [_pFourDownLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(_pThreeDownLabel);
        make.right.mas_equalTo(self);
        make.width.mas_equalTo(@[_pOneDownLabel, _pTwoDownLabel, _pThreeDownLabel]);
    }];
}

- (void)p_updateDataWithmodel:(HZPeiziMoneyFlowModel *)model indexPath:(NSIndexPath *)indexPath
{
    [self p_cleaOldData];
    [self p_updateNewData:model];
}
- (void)p_updateNewData:(HZPeiziMoneyFlowModel *)model
{
    _pOneLabel.text = model.mode_one;
    _pTwoLabel.text = model.mode_two;
    _pThreeLabel.text = model.mode_three;
    _pFourLabel.text = model.mode_four;
    _pOneDownLabel.text = model.mode_downOne;
    _pTwoDownLabel.text = model.mode_downTwo;
    _pThreeDownLabel.text = model.mode_downThree;
    _pFourDownLabel.text = model.mode_downFour;
    if (model.mode_type == kCell_Trade_Type) {
        UIColor *color = [UIColor blackColor];
        if ([model.mode_two floatValue] < 0) {
            color = kGREENColor;
        }else if ([model.mode_two floatValue] > 0) {
            color = kREDColor;
        }
        _pOneLabel.textColor = color;
        _pTwoLabel.textColor = color;
        _pThreeLabel.textColor = color;
        _pFourLabel.textColor = color;
        _pOneDownLabel.textColor = color;
        _pTwoDownLabel.textColor = color;
        _pThreeDownLabel.textColor = color;
        _pFourDownLabel.textColor = color;
    }else {
        UIColor *color = [UIColor blackColor];
        if ([model.mode_downThree floatValue] < 0) {
            color = kGREENColor;
        }else if ([model.mode_downThree floatValue] > 0) {
            color = kREDColor;
        }
        _pThreeDownLabel.textColor = color;
    }
}
- (void)p_cleaOldData
{
    [_pOneLabel setText:@""];
    [_pTwoLabel setText:@""];
    [_pThreeLabel setText:@""];
    [_pFourLabel setText:@""];
    [_pOneDownLabel setText:@""];
    [_pTwoDownLabel setText:@""];
    [_pThreeDownLabel setText:@""];
    [_pFourDownLabel setText:@""];
}


@end
